<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Like
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: DisplayLikes.php 2010-09-07 16:05 idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Like
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Like_View_Helper_LikeMenu extends Engine_View_Helper_HtmlImage
{
  public function likeMenu()
  {
    $viewer = Engine_Api::_()->user()->getViewer();
    $subject = Engine_Api::_()->core()->getSubject();
    
    if( !$viewer->getIdentity()){
      return false;
    }

    $menu = $this->getAppropriateMenu($viewer, $subject);
    $rendered = $this->render($menu);

    $wrapper = "<div class='like_container_menu_wrapper'>"
      . "<a title='" . $this->view->translate('like_Show Like') . "' class='like_menu_switcher' href='javascript:void(0)' onFocus='this.blur();' onClick='like.toggle_menu(this);'>+</a>"
      . $rendered
      . "<div class='clr'></div>"
      . "</div>";

    return $wrapper;
  }

  public function render($menu)
  {
    if (empty($menu)){
      return "";
    }

    $output = "<div class='like_profile_menu hidden'>";
    foreach ($menu as $item){
      $url = Zend_Controller_Front::getInstance()->getRouter()->assemble($item['params'], $item['route']);
      $background = $item['icon'];
      $title = $item['title'] ? 'title="' . $this->view->translate($item['title']) . '"' : '';
      $html = "<div class='like_profile_item_container'> " .
        " <a " . $title . " style='background-image: url(" . $background . ");' class='buttonlink like_profile_item_item " . $item['class'] . "' href='" . $url . "'> " .
        " <span> " . $this->view->translate($item['label']) . " </span> " .
        " </a> " .
        "</div>";

      $output .= $html;
    }
    
    $output .= "<div class='clr'></div></div>";

    return $output;
  }

  public function getAppropriateMenu($viewer, $subject)
  {
  	if ($subject->getType() == 'page'){
  		$func = "isTeamMember";
  	}else{
  		$func = "isOwner";
  	}

    $menu = array();
  	if ($subject->$func($viewer)){
    	if (Engine_Api::_()->like()->isEnabledLikeClub($subject)){
    		$menu_item = array(
		      'label' => "like_Disable",
          'title' => 'like_Disable likes. Members can not be able to like this.',
		      'icon' => 'application/modules/Like/externals/images/disable_like_club.png',
		      'route' => 'like_club',
    			'class' => 'disable_like_club',
		      'params' => array(
		        'action' => 'manage',
		        'object_id' => $subject->getIdentity(),
    				'object' => $subject->getType(),
    				'active' => 0
		      )
		    );

        $class = '';
    	}
    	else{
    		$menu_item = array(
		      'label' => "like_Enable",
          'title' => 'like_Enable likes. Members can like this.',
		      'icon' => 'application/modules/Like/externals/images/enable_like_club.png',
		      'route' => 'like_club',
    			'class' => 'enable_like_club',
		      'params' => array(
		        'action' => 'manage',
		        'object_id' => $subject->getIdentity(),
    				'object' => $subject->getType(),
    				'active' => 1
		      )
		    );

        $class = ' like_display_none';
    	}
    }

    $menu[] = $menu_item;

    $menu[] = array(
      'label' => 'like_Suggest',
      'title' => 'like_Suggest to friends, may be they will like it.',
      'icon' => 'application/modules/Like/externals/images/suggest.png',
      'route' => 'like_club',
      'class' => 'like_suggest'.$class,
      'params' => array(
        'action' => 'suggest',
        'object' => $subject->getType(),
        'object_id' => $subject->getIdentity()
      )
    );

    $menu[] = array(
      'label' => 'like_Send',
      'title' => 'like_Send any internal message and e-mail for those members who liked it.',
      'icon' => 'application/modules/Like/externals/images/send_update.png',
      'class' => "smoothbox like_send_update".$class,
      'route' => 'like_club',
      'params' => array(
        'action' => 'send-update',
        'object_id' => $subject->getIdentity(),
        'object' => $subject->getType()
      )
    );

    $menu[] = array(
      'label' => 'like_Promote',
      'title' => 'like_Promote your content in Internet by Like Box or Like Button widgets.',
      'icon' => 'application/modules/Like/externals/images/add_like_box.png',
      'class' => "smoothbox like_promote".$class,
      'route' => 'like_club',
      'params' => array(
        'action' => 'promote',
        'object_id' => $subject->getIdentity(),
        'object' => $subject->getType()
      )
    );

    if ($subject->getType() == 'user'){
    $menu[] = array(
      'label' => 'like_I liked',
      'title' => 'like_Users and pages that you liked.',
      'icon' => 'application/modules/Like/externals/images/my_like_clubs.png',
      'route' => 'like_default',
      'class' => 'my_like_clubs',
      'params' => array(
        'action' => 'index'
      )
    );
    }

    return $menu;
  }
}